package com.spl.seriallibrary.locker.metalcar;

import android.content.Context;

import com.spl.seriallibrary.locker.IHandle;
import com.spl.seriallibrary.util.Constant;
import com.spl.seriallibrary.util.SerialPortTools;

public class MetalCarHandle implements IHandle {

    @Override
    public Object checkData(byte[] LISHIZHI, byte[] buffer) {
        if (LISHIZHI.length == 1 && buffer[0] == 9) {
            return Constant.CheckResultTYPE.OVERTIME;
        }
        if (LISHIZHI.length > 4) {
            return Constant.CheckResultTYPE.RESULT_OK;
        } else {
            return Constant.CheckResultTYPE.NOT_ENOUGH_LENGTH;
        }
    }

    @Override
    public boolean stateQuerySingleLock(byte[] LISHIZHI, String boxId, Context context) {
        String state = SerialPortTools.byteToHexStr(LISHIZHI.length, LISHIZHI).substring(6, 8);
        return "11".equals(state);
    }

    @Override
    public boolean stateOpenSingleLock(byte[] LISHIZHI, String boxId, Context context) {
        String state = SerialPortTools.byteToHexStr(LISHIZHI.length, LISHIZHI).substring(6, 8);
        return "11".equals(state);
    }
}
